package com.example.demo.config;

import com.example.demo.websocket.SpeechRecognitionWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SpeechRecognitionWebSocketHandler speechRecognitionWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册语音识别WebSocket处理器
        registry.addHandler(speechRecognitionWebSocketHandler, "/ws/speech-recognition", "/speech", "/ws/speech")
                .setAllowedOrigins("*"); // 允许跨域，生产环境建议配置具体域名
    }
}